﻿// Open Source: MIT License (http://www.opensource.org/licenses/mit-license.php)
// Project: YoProgramo.NET (http://code.google.com/p/yoprogramo/)
// Autor: Fabian Figueredo (info@fabianfigueredo.com.ar)
// Blog: blog.yoprogramo.net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YoProgramo.Domain.Core;
using YoProgramo.Domain.Core.Entities;
using YoProgramo.Domain.Core.Interfaces;

namespace YoProgramo.Infrastructure.Data.Repositories
{
    public class UserRepository : RepositoryBase<IUser, User, long>, IUserRepository {

        public IUser FindByUserName(string userName)
        {
            Check.Require(!String.IsNullOrEmpty(userName), "Usuario no puede ser nulo");
            return dao.GetAll().FirstOrDefault(w => w.UserName == userName) as IUser;
        }

        public IUser FindByUserNameAndPassword(string userName, string password)
        {
            Check.Require(!String.IsNullOrEmpty(userName), "Usuario no puede ser nulo");
            Check.Require(!String.IsNullOrEmpty(password), "Password no puede ser nulo");
            return dao.GetAll().FirstOrDefault(w => w.UserName == userName && w.Password == password) as IUser;
        }

        public IUser FindByEmail(string email)
        {
            Check.Require(!String.IsNullOrEmpty(email), "Email no puede ser nulo");


            return dao.GetAll().FirstOrDefault(w => w.Email == email) as IUser;
        }


        public long? FindScoreByUserName(string userName, DateTime startTimestamp, DateTime endTimestamp) {
            //Hacer un check aca
            IUser user = dao.GetAll().FirstOrDefault(w => w.UserName == userName) as IUser;
            return user.Reputation;
        }

        public IList<IUser> FindTop(DateTime startTimestamp, DateTime endTimestamp, int start, int max)
        {
            throw new NotImplementedException();
        }

        public IList<IUser> FindAll(int start, int max)
        {
            throw new NotImplementedException();
        }

        public ICollection<string> FindIPAddresses(Guid id)
        {
            throw new NotImplementedException();
        }

    }
}